package com.photoeditor.demo.util.update;

import android.content.Context;

import com.photoeditor.R;
import com.photoeditor.demo.util.update.dialog.NoUpdateDialog;
import com.photoeditor.demo.util.update.dialog.UpdateDialog;

/**
 * 作用及描述：更新弹窗
 */
public class UpdateDialogUtil {
    private Context mContext;
    private UpdateDialog mUpdateDialog;
    private UpdateUtil.UpdateInfo mUpdateInfo;

    public UpdateDialogUtil(Context context) {
        mContext = context;
    }

    public void showUpdateDialog(String title, String content, UpdateUtil.UpdateInfo updateInfo) {
        if (mContext == null || updateInfo == null) {
            return;
        }
        mUpdateInfo = updateInfo;
        mUpdateDialog = new UpdateDialog(mContext, mUpdateInfo);
        mUpdateDialog.setMessage(content);
        mUpdateDialog.setTitle(title);
        mUpdateDialog.show();
    }

    public boolean isUpdateDialogShowing() {
        return mUpdateDialog != null && mUpdateDialog.isShowing();
    }

    public void hideUpdateDialog() {
        if (mUpdateDialog != null && mUpdateDialog.isShowing()) {
            mUpdateDialog.dismiss();
        }
        mUpdateDialog = null;
    }


    public void showNoUpdateDialog() {
        NoUpdateDialog noUpdateDialog = new NoUpdateDialog(mContext);
        noUpdateDialog.show();
    }


    public void showNoNetworkDialog() {
        NoUpdateDialog noNetworkDialog = new NoUpdateDialog(mContext);
        noNetworkDialog.setContentText(R.string.no_network);
        noNetworkDialog.show();
    }

    public void release() {
        if (mUpdateDialog != null) {
            if (mUpdateDialog.isShowing()) mUpdateDialog.dismiss();
            mUpdateDialog = null;
        }
        mContext = null;
    }
}
